package com.usabb.service.impl;

import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.stereotype.Service;

import com.usabb.dao.LabelRelationDao;
import com.usabb.domain.LabelRelationDO;
import com.usabb.service.LabelRelationService;
import com.ifast.common.base.CoreServiceImpl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * <pre>
 * 标签关联表
 * </pre>
 * <small> 2019-08-19 18:03:26 | Aron</small>
 */
@Slf4j
@Service
public class LabelRelationServiceImpl extends CoreServiceImpl<LabelRelationDao, LabelRelationDO> implements LabelRelationService {

    @Override
    public void addAll(Long bizId, Long[] labelIds) {
        if (ArrayUtils.isEmpty(labelIds)) {
            log.info("LabelRelation add - ids is null ");
            return;
        }

        List<LabelRelationDO> relationDOList = Lists.newArrayListWithCapacity(labelIds.length);
        for (Long labelId : labelIds) {
            relationDOList.add(LabelRelationDO.of(bizId, labelId));
        }

        this.insertBatch(relationDOList);
    }

    @Override
    public List<LabelRelationDO> getAllByBizId(Long bizId) {
        Map<String, Object> paramMap = new HashMap<>(1);
        paramMap.put("bizId", bizId);

        return this.selectByMap(paramMap);
    }


}
